//
//  AppleScriptSlice.m
//  Pennyworth Punch Clock
//
//  Created by Chris Karr on 7/24/08.
//  Copyright 2008 Northwestern University. All rights reserved.
//

#import "AppleScriptSlice.h"


@implementation AppleScriptSlice

@synthesize name;
@synthesize startDate;
@synthesize endDate;
@synthesize stream;

- (NSScriptObjectSpecifier *) objectSpecifier 
{
	NSArray * slices = [stream valueForKey:@"slices"];
	
	NSUInteger index = NSNotFound;
	
	NSUInteger i = 0;
	for (i = 0; i < [slices count] && index == NSNotFound; i++)
	{
		AppleScriptSlice * slice = [slices objectAtIndex:i];
		
		if ([slice.name isEqualToString:self.name])
			index = i;
	}
	
    if (index != NSNotFound) 
	{
		NSScriptObjectSpecifier * containerRef = [stream objectSpecifier];
		
        return [[[NSIndexSpecifier alloc] initWithContainerClassDescription:[containerRef keyClassDescription] 
														 containerSpecifier:containerRef key:@"slices" index:index] autorelease];
    }
	else
        return nil;
}

@end
